!function() {
	function e() {}
	e.prototype.start = function(e) {
		var t = this;
		t.routerMap = e.router,
		t.mainView = e.view,
		t.errorTemplateId = e.errorTemplateId,
		n(),
		window.onhashchange = function() {
			n()
		}
	};
	var t = [];
	function r(e) {
		var t = vipspa.routerMap[e.url];
		if (void 0 === t) {
			var r = vipspa.routerMap.defaults;
			return t = vipspa.routerMap[r],
			location.hash = r,
			!1
		}
		$.ajax({
			type: "GET",
			url: t.templateUrl,
			dataType: "html",
			success: function(e, r, n) {
				var a, o, i, p;
				$(vipspa.mainView).html(e),
				a = t.controller,
				(p = document.createElement("script")).setAttribute("src", a),
				p.onreadystatechange = p.onload = function() {
					p.onreadystatechange = null,
					document.documentElement.removeChild(p),
					p = null,
					i || "function" == typeof o && o(),
					i = !0
				},
				document.documentElement.appendChild(p)
			},
			error: function(e, t, r) {
				if (0 === $(vipspa.errorTemplateId).length) return ! 1;
				var n = $(vipspa.errorTemplateId).html();
				n = (n = n.replace(/{{errStatus}}/, e.status)).replace(/{{errContent}}/, e.responseText),
				$(vipspa.mainView).html(n)
			}
		})
	}
	function n() {
		var e = location.hash;
		r(vipspa.parse(e))
	}
	e.prototype.getMessage = function(e) {
		var r = {};
		return $.each(t,
		function(t, n) {
			n.id === e && (r = n)
		}),
		r
	},
	e.prototype.setMessage = function(e) {
		var r = JSON.parse(JSON.stringify(e));
		$.each(t,
		function(e, t) {
			if (t.id === r.id) return t = r,
			!1
		}),
		t.push(r)
	},
	e.prototype.delMessage = function(e) {
		if (void 0 === e) return ! 1;
		var r = 0;
		$.each(t,
		function(t, n) {
			n.id === e && (r = t)
		}),
		$.each(t,
		function(e, n) {
			e > r && (t[e - 1] = n)
		})
	},
	e.prototype.clearMessage = function(e) {
		t = []
	},
	e.prototype.stringify = function(e, t) {
		var r = "";
		for (var n in t) r += n + "=" + encodeURIComponent(t[n]) + "&";
		return "" === r ? e: e + "?" + (r = r.substring(0, r.length - 1))
	},
	e.prototype.parse = function(e) {		
		var t = void 0 === e ? location.hash: e,
		r = {},
		n = "",
		a = t.indexOf("?");
		if ("" === t) return {
			url: "",
			param: {}
		};
		if (a > -1) {
			n = t.substring(1, a);
			var o = t.substring(a + 1).split("&");
			$.each(o,
			function(e, t) {
				var n, a, o = t.split("=");
				n = o[0],
				a = o[1],
				"" !== n && (r[n] = decodeURIComponent(a))
			})
		} else n = t.substring(1),
		r = {};
		return {
			url: n,
			param: r
		}
	},
	window.vipspa = new e
} ();